<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>comments - RDoc Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="file">
  <!-- this is page.html -->
  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->


 <div class='wrapper hdiv'>

 


<nav id='vapp' role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#label-Code+Comments">Code Comments</a>
    <li><a href="#label-Magic+Comments">Magic Comments</a>
    <li><a href="#label-Alternative+syntax">Alternative syntax</a>
    <li><a href="#label-encoding+Directive"><code>encoding</code> Directive</a>
    <li><a href="#label-frozen_string_literal+Directive"><code>frozen_string_literal</code> Directive</a>
    <li><a href="#label-warn_indent+Directive"><code>warn_indent</code> Directive</a>
    <li><a href="#label-shareable_constant_value+Directive"><code>shareable_constant_value</code> Directive</a>
    <li><a href="#label-Mode+none+-28default-29">Mode <code>none</code> (default)</a>
    <li><a href="#label-Mode+literal">Mode <code>literal</code></a>
    <li><a href="#label-Mode+experimental_everything">Mode <code>experimental_everything</code></a>
    <li><a href="#label-Mode+experimental_copy">Mode <code>experimental_copy</code></a>
    <li><a href="#label-Scope">Scope</a>
  </ul>
</div>

  <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>

  <div id="project-metadata">
   <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
    
<div id="fileindex-section" class="nav-section">
  <h3>Pages</h3>

  <ul class="link-list">
    <li><a href="../NEWS/NEWS-1_8_7.html">NEWS-1.8.7</a>
    <li><a href="../NEWS/NEWS-1_9_1.html">NEWS-1.9.1</a>
    <li><a href="../NEWS/NEWS-1_9_2.html">NEWS-1.9.2</a>
    <li><a href="../NEWS/NEWS-1_9_3.html">NEWS-1.9.3</a>
    <li><a href="../NEWS/NEWS-2_0_0.html">NEWS-2.0.0</a>
    <li><a href="../NEWS/NEWS-2_1_0.html">NEWS-2.1.0</a>
    <li><a href="../NEWS/NEWS-2_2_0.html">NEWS-2.2.0</a>
    <li><a href="../NEWS/NEWS-2_3_0.html">NEWS-2.3.0</a>
    <li><a href="../NEWS/NEWS-2_4_0.html">NEWS-2.4.0</a>
    <li><a href="../NEWS/NEWS-2_5_0.html">NEWS-2.5.0</a>
    <li><a href="../NEWS/NEWS-2_6_0.html">NEWS-2.6.0</a>
    <li><a href="../NEWS/NEWS-2_7_0.html">NEWS-2.7.0</a>
    <li><a href="../NEWS/NEWS-3_0_0_md.html">NEWS-3.0.0</a>
    <li><a href="../NEWS/NEWS-3_1_0_md.html">NEWS-3.1.0</a>
    <li><a href="../NEWS/NEWS-3_2_0_md.html">NEWS-3.2.0</a>
    <li><a href="../bsearch_rdoc.html">bsearch</a>
    <li><a href="../bug_triaging_rdoc.html">bug_triaging</a>
    <li><a href="../case_mapping_rdoc.html">case_mapping</a>
    <li><a href="../character_selectors_rdoc.html">character_selectors</a>
    <li><a href="../command_injection_rdoc.html">command_injection</a>
    <li><a href="../contributing_md.html">contributing</a>
    <li><a href="../contributing/building_ruby_md.html">building_ruby</a>
    <li><a href="../contributing/documentation_guide_md.html">documentation_guide</a>
    <li><a href="../contributing/glossary_md.html">glossary</a>
    <li><a href="../contributing/making_changes_to_ruby_md.html">making_changes_to_ruby</a>
    <li><a href="../contributing/making_changes_to_stdlibs_md.html">making_changes_to_stdlibs</a>
    <li><a href="../contributing/reporting_issues_md.html">reporting_issues</a>
    <li><a href="../contributing/testing_ruby_md.html">testing_ruby</a>
    <li><a href="../dig_methods_rdoc.html">dig_methods</a>
    <li><a href="../distribution_md.html">distribution</a>
    <li><a href="../dtrace_probes_rdoc.html">dtrace_probes</a>
    <li><a href="../encodings_rdoc.html">encodings</a>
    <li><a href="../extension_ja_rdoc.html">extension.ja</a>
    <li><a href="../extension_rdoc.html">extension</a>
    <li><a href="../fiber_md.html">fiber</a>
    <li><a href="../format_specifications_rdoc.html">format_specifications</a>
    <li><a href="../globals_rdoc.html">globals</a>
    <li><a href="../implicit_conversion_rdoc.html">implicit_conversion</a>
    <li><a href="../keywords_rdoc.html">keywords</a>
    <li><a href="../maintainers_md.html">maintainers</a>
    <li><a href="../marshal_rdoc.html">marshal</a>
    <li><a href="../memory_view_md.html">memory_view</a>
    <li><a href="../optparse/argument_converters_rdoc.html">argument_converters</a>
    <li><a href="../optparse/creates_option_rdoc.html">creates_option</a>
    <li><a href="../optparse/option_params_rdoc.html">option_params</a>
    <li><a href="../optparse/tutorial_rdoc.html">tutorial</a>
    <li><a href="../packed_data_rdoc.html">packed_data</a>
    <li><a href="../ractor_md.html">ractor</a>
    <li><a href="../regexp_rdoc.html">regexp</a>
    <li><a href="../regexp/methods_rdoc.html">methods</a>
    <li><a href="../regexp/unicode_properties_rdoc.html">unicode_properties</a>
    <li><a href="../ruby_3_3_0_preview2/COPYING.html">COPYING</a>
    <li><a href="../ruby_3_3_0_preview2/COPYING_ja.html">COPYING.ja</a>
    <li><a href="../ruby_3_3_0_preview2/LEGAL.html">LEGAL</a>
    <li><a href="../ruby_3_3_0_preview2/NEWS_md.html">NEWS</a>
    <li><a href="../ruby_3_3_0_preview2/README_ja_md.html">README.ja</a>
    <li><a href="../ruby_3_3_0_preview2/README_md.html">README</a>
    <li><a href="../security_rdoc.html">security</a>
    <li><a href="../signals_rdoc.html">signals</a>
    <li><a href="../standard_library_rdoc.html">standard_library</a>
    <li><a href="../strftime_formatting_rdoc.html">strftime_formatting</a>
    <li><a href="../syntax_rdoc.html">syntax</a>
    <li><a href="../syntax/assignment_rdoc.html">assignment</a>
    <li><a href="../syntax/calling_methods_rdoc.html">calling_methods</a>
    <li><a href="../syntax/comments_rdoc.html">comments</a>
    <li><a href="../syntax/control_expressions_rdoc.html">control_expressions</a>
    <li><a href="../syntax/exceptions_rdoc.html">exceptions</a>
    <li><a href="../syntax/literals_rdoc.html">literals</a>
    <li><a href="../syntax/methods_rdoc.html">methods</a>
    <li><a href="../syntax/miscellaneous_rdoc.html">miscellaneous</a>
    <li><a href="../syntax/modules_and_classes_rdoc.html">modules_and_classes</a>
    <li><a href="../syntax/pattern_matching_rdoc.html">pattern_matching</a>
    <li><a href="../syntax/precedence_rdoc.html">precedence</a>
    <li><a href="../syntax/refinements_rdoc.html">refinements</a>
    <li><a href="../timezones_rdoc.html">timezones</a>
    <li><a href="../windows_md.html">windows</a>
    <li><a href="../yjit/yjit_md.html">yjit</a>
    <li><a href="../yjit/yjit_hacking_md.html">yjit_hacking</a>
  </ul>
</div>

   </div>
  </div>
</nav>


<!--  carbon ads here -->

<div id='extraz'>
  <div class='adzbox-index'  >
   
  </div>
 </div>         


<main role="main" aria-label="Page syntax/comments.rdoc">

<h1 id="label-Code+Comments">Code Comments<span><a href="#label-Code+Comments">&para;</a> <a href="#top">&uarr;</a></span></h1>

<p>Ruby has two types of comments: inline and block.</p>

<p>Inline comments start with the <code>#</code> character and continue until the end of the line:</p>

<pre class="ruby"><span class="ruby-comment"># On a separate line</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">Foo</span> <span class="ruby-comment"># or at the end of the line</span>
  <span class="ruby-comment"># can be indented</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bar</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Block comments start with <code>=begin</code> and end with <code>=end</code>. Each should start on a separate line.</p>

<pre class="ruby"><span class="ruby-comment">=begin
This is
commented out
=end</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">Foo</span>
<span class="ruby-keyword">end</span>

<span class="ruby-comment">=begin some_tag
this works, too
=end</span>
</pre>

<p><code>=begin</code> and <code>=end</code> can not be indented, so this is a syntax error:</p>

<pre>class Foo
  =begin
  Will not work
  =end
end</pre>

<h2 id="label-Magic+Comments">Magic Comments<span><a href="#label-Magic+Comments">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>While comments are typically ignored by Ruby, special “magic comments” contain directives that affect how the code is interpreted.</p>

<p>Top-level magic comments must appear in the first comment section of a file.</p>

<p>NOTE: Magic comments affect only the file in which they appear; other files are unaffected.</p>

<pre class="ruby"><span class="ruby-comment"># frozen_string_literal: true</span>

<span class="ruby-identifier">var</span> = <span class="ruby-string">&#39;hello&#39;</span>
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<h3 id="label-Alternative+syntax">Alternative syntax<span><a href="#label-Alternative+syntax">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Magic comments may consist of a single directive (as in the example above). Alternatively, multiple directives may appear on the same line if separated by “;” and wrapped between “-*-” (see Emacs’ <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html">file variables</a>).</p>

<pre class="ruby"><span class="ruby-comment"># emacs-compatible; -*- coding: big5; mode: ruby; frozen_string_literal: true -*-</span>

<span class="ruby-identifier">p</span> <span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">p</span> <span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:Big5&gt;</span>
</pre>

<h3 id="label-encoding+Directive"><code>encoding</code> Directive<span><a href="#label-encoding+Directive">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Indicates which string encoding should be used for string literals, regexp literals and <code>__ENCODING__</code>:</p>

<pre class="ruby"><span class="ruby-comment"># encoding: big5</span>

<span class="ruby-string">&#39;&#39;</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:Big5&gt;</span>
</pre>

<p>Default encoding is UTF-8.</p>

<p>Top-level magic comments must start on the first line, or on the second line if the first line looks like <code>#! shebang line</code>.</p>

<p>The word “coding” may be used instead of “encoding”.</p>

<h3 id="label-frozen_string_literal+Directive"><code>frozen_string_literal</code> Directive<span><a href="#label-frozen_string_literal+Directive">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Indicates that string literals should be allocated once at parse time and frozen.</p>

<pre class="ruby"><span class="ruby-comment"># frozen_string_literal: true</span>

<span class="ruby-value">3</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span>
  <span class="ruby-identifier">p</span> <span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-comment"># =&gt; prints same number</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">p</span> <span class="ruby-string">&#39;world&#39;</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>The default is false; this can be changed with <code>--enable=frozen-string-literal</code>. Without the directive, or with <code># frozen_string_literal: false</code>, the example above would print 3 different numbers and “false”.</p>

<p>Starting in Ruby 3.0, string literals that are dynamic are not frozen nor reused:</p>

<pre class="ruby"><span class="ruby-comment"># frozen_string_literal: true</span>

<span class="ruby-identifier">p</span> <span class="ruby-node">&quot;Addition: #{2 + 2}&quot;</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>It must appear in the first comment section of a file.</p>

<h3 id="label-warn_indent+Directive"><code>warn_indent</code> Directive<span><a href="#label-warn_indent+Directive">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>This directive can turn on detection of bad indentation for statements that follow it:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
  <span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; no warning</span>

<span class="ruby-comment"># warn_indent: true</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bar</span>
  <span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; warning: mismatched indentations at &#39;end&#39; with &#39;def&#39; at 6</span>
</pre>

<p>Another way to get these warnings to show is by running Ruby with warnings (<code>ruby -w</code>). Using a directive to set this false will prevent these warnings to show.</p>

<h3 id="label-shareable_constant_value+Directive"><code>shareable_constant_value</code> Directive<span><a href="#label-shareable_constant_value+Directive">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Note: This directive is experimental in Ruby 3.0 and may change in future releases.</p>

<p>This special directive helps to create constants that hold only immutable objects, or <a href="../Ractor.html#class-Ractor-label-Shareable+and+unshareable+objects">Ractor-shareable</a> constants.</p>

<p>The directive can specify special treatment for values assigned to constants:</p>
<ul><li>
<p><code>none</code>: (default)</p>
</li><li>
<p><code>literal</code>: literals are implicitly frozen, others must be Ractor-shareable</p>
</li><li>
<p><code>experimental_everything</code>: all made shareable</p>
</li><li>
<p><code>experimental_copy</code>: copy deeply and make it shareable</p>
</li></ul>

<h4 id="label-Mode+none+-28default-29">Mode <code>none</code> (default)<span><a href="#label-Mode+none+-28default-29">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>No special treatment in this mode (as in Ruby 2.x): no automatic freezing and no checks.</p>

<p>It has always been a good idea to deep-freeze constants; <a href="../Ractor.html"><code>Ractor</code></a> makes this an even better idea as only the main ractor can access non-shareable constants:</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: none</span>
<span class="ruby-constant">A</span> = {<span class="ruby-value">foo:</span> []}
<span class="ruby-constant">A</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-constant">Ractor</span>.<span class="ruby-identifier">new</span> { <span class="ruby-identifier">puts</span> <span class="ruby-constant">A</span> } <span class="ruby-comment"># =&gt; can not access non-shareable objects by non-main Ractor.</span>
</pre>

<h4 id="label-Mode+literal">Mode <code>literal</code><span><a href="#label-Mode+literal">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>In “literal” mode, constants assigned to literals will be deeply-frozen:</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: literal</span>
<span class="ruby-constant">X</span> = [{<span class="ruby-value">foo:</span> []}] <span class="ruby-comment"># =&gt; same as [{foo: [].freeze}.freeze].freeze</span>
</pre>

<p>Other values must be shareable:</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: literal</span>
<span class="ruby-constant">X</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment"># =&gt; cannot assign unshareable object to X</span>
</pre>

<p>Note that only literals directly assigned to constants, or recursively held in such literals will be frozen:</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: literal</span>
<span class="ruby-identifier">var</span> = [{<span class="ruby-value">foo:</span> []}]
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false (assignment was made to local variable)</span>
<span class="ruby-constant">X</span> = <span class="ruby-identifier">var</span> <span class="ruby-comment"># =&gt; cannot assign unshareable object to X</span>

<span class="ruby-constant">X</span> = <span class="ruby-constant">Set</span>[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, {<span class="ruby-value">foo:</span> []}].<span class="ruby-identifier">freeze</span> <span class="ruby-comment"># =&gt; cannot assign unshareable object to X</span>
                                <span class="ruby-comment"># (`Set[...]` is not a literal and</span>
                                <span class="ruby-comment"># `{foo: []}` is an argument to `Set.[]`)</span>
</pre>

<p>The method <a href="../Module.html#method-i-const_set"><code>Module#const_set</code></a> is not affected.</p>

<h4 id="label-Mode+experimental_everything">Mode <code>experimental_everything</code><span><a href="#label-Mode+experimental_everything">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>In this mode, all values assigned to constants are made shareable.</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: experimental_everything</span>
<span class="ruby-constant">FOO</span> = <span class="ruby-constant">Set</span>[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, {<span class="ruby-value">foo:</span> []}]
<span class="ruby-comment"># same as FOO = Ractor.make_sharable(...)</span>
<span class="ruby-comment"># OR same as `FOO = Set[1, 2, {foo: [].freeze}.freeze].freeze`</span>

<span class="ruby-identifier">var</span> = [{<span class="ruby-value">foo:</span> []}]
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false (assignment was made to local variable)</span>
<span class="ruby-constant">X</span> = <span class="ruby-identifier">var</span> <span class="ruby-comment"># =&gt; calls `Ractor.make_shareable(var)`</span>
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>This mode is “experimental”, because it might be error prone, for example by deep-freezing the constants of an external resource which could cause errors:</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: experimental_everything</span>
<span class="ruby-constant">FOO</span> = <span class="ruby-constant">SomeGem</span><span class="ruby-operator">::</span><span class="ruby-constant">Something</span><span class="ruby-operator">::</span><span class="ruby-constant">FOO</span>
<span class="ruby-comment"># =&gt; deep freezes the gem&#39;s constant!</span>
</pre>

<p>This will be revisited before Ruby 3.1 to either allow ‘everything` or to instead remove this mode.</p>

<p>The method <a href="../Module.html#method-i-const_set"><code>Module#const_set</code></a> is not affected.</p>

<h4 id="label-Mode+experimental_copy">Mode <code>experimental_copy</code><span><a href="#label-Mode+experimental_copy">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>In this mode, all values assigned to constants are deeply copied and made shareable. It is safer mode than <code>experimental_everything</code>.</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: experimental_copy</span>
<span class="ruby-identifier">var</span> = [{<span class="ruby-value">foo:</span> []}]
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false (assignment was made to local variable)</span>
<span class="ruby-constant">X</span> = <span class="ruby-identifier">var</span> <span class="ruby-comment"># =&gt; calls `Ractor.make_shareable(var, copy: true)`</span>
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-constant">Ractor</span>.<span class="ruby-identifier">shareable?</span>(<span class="ruby-constant">X</span>) <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">var</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-constant">X</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-comment">#=&gt; false</span>
</pre>

<p>This mode is “experimental” and has not been discussed thoroughly. This will be revisited before Ruby 3.1 to either allow ‘copy` or to instead remove this mode.</p>

<p>The method <a href="../Module.html#method-i-const_set"><code>Module#const_set</code></a> is not affected.</p>

<h4 id="label-Scope">Scope<span><a href="#label-Scope">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This directive can be used multiple times in the same file:</p>

<pre class="ruby"><span class="ruby-comment"># shareable_constant_value: none</span>
<span class="ruby-constant">A</span> = {<span class="ruby-value">foo:</span> []}
<span class="ruby-constant">A</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-constant">Ractor</span>.<span class="ruby-identifier">new</span> { <span class="ruby-identifier">puts</span> <span class="ruby-constant">A</span> } <span class="ruby-comment"># =&gt; can not access non-shareable objects by non-main Ractor.</span>

<span class="ruby-comment"># shareable_constant_value: literal</span>
<span class="ruby-constant">B</span> = {<span class="ruby-value">foo:</span> []}
<span class="ruby-constant">B</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">B</span>[<span class="ruby-value">:foo</span>].<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>

<span class="ruby-constant">C</span> = [<span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>] <span class="ruby-comment"># =&gt; cannot assign unshareable object to C (Ractor::IsolationError)</span>

<span class="ruby-constant">D</span> = [<span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">freeze</span>]
<span class="ruby-constant">D</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>

<span class="ruby-comment"># shareable_constant_value: experimental_everything</span>
<span class="ruby-constant">E</span> = <span class="ruby-constant">Set</span>[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>]
<span class="ruby-constant">E</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">E</span>.<span class="ruby-identifier">all</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:frozen?</span>) <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>The directive affects only subsequent constants and only for the current scope:</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">Mod</span>
  <span class="ruby-comment"># shareable_constant_value: literal</span>
  <span class="ruby-constant">A</span> = [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]
  <span class="ruby-keyword">module</span> <span class="ruby-constant">Sub</span>
    <span class="ruby-constant">B</span> = [<span class="ruby-value">4</span>, <span class="ruby-value">5</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">C</span> = [<span class="ruby-value">4</span>, <span class="ruby-value">5</span>]

<span class="ruby-keyword">module</span> <span class="ruby-constant">Mod</span>
  <span class="ruby-constant">D</span> = [<span class="ruby-value">6</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">p</span> <span class="ruby-constant">Mod</span><span class="ruby-operator">::</span><span class="ruby-constant">A</span>.<span class="ruby-identifier">frozen?</span>, <span class="ruby-constant">Mod</span><span class="ruby-operator">::</span><span class="ruby-constant">Sub</span><span class="ruby-operator">::</span><span class="ruby-constant">B</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; true, true</span>
<span class="ruby-identifier">p</span> <span class="ruby-constant">C</span>.<span class="ruby-identifier">frozen?</span>, <span class="ruby-constant">Mod</span><span class="ruby-operator">::</span><span class="ruby-constant">D</span>.<span class="ruby-identifier">frozen?</span> <span class="ruby-comment"># =&gt; false, false</span>
</pre>

</main>

</div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

